package com.dwjm.shop.Jbp.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionDatabaseForSQLSeverUseJdbc {
    //连接数据库的驱动
    private static final String DRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";

    //连接数据库的URL
    private static final String URL = "jdbc:sqlserver://124.221.132.179:1433;databaseName=9_Group";

    //数据库用户名
    private static final String USERNAME = "sa";


    //数据库密码
    private static final String PASSWORD = "9342567897jbp";


    //定义一个方法，用于获取数据库连接
    static Connection connection = null;

    //连接数据库函数
    public static Connection getConnection(){
        try {
            Class.forName(DRIVER);
            connection= DriverManager.getConnection(URL, USERNAME, PASSWORD);
            return connection;
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        return null;
    }
    public static void main(String[] args){
        System.out.println(getConnection()==null);
    }
}
